| Visual Basic (Declaration) | |
|---|---|
<DescriptionAttribute("Send data from your buffer.")> Public Overloads Function Send( _ ByVal buffer() As Byte, _ ByVal offset As Integer, _ ByVal count As Integer, _ ByVal socketFlags As SocketFlags _ ) As Segment | |
| Visual Basic (Usage) | Copy Code |
|---|---|
Dim instance As Tcp Dim buffer() As Byte Dim offset As Integer Dim count As Integer Dim socketFlags As SocketFlags Dim value As Segment value = instance.Send(buffer, offset, count, socketFlags) | |
| C# | |
|---|---|
[DescriptionAttribute("Send data from your buffer.")] public Segment Send( byte[] buffer, int offset, int count, SocketFlags socketFlags ) | |
| Managed Extensions for C++ | |
|---|---|
[DescriptionAttribute("Send data from your buffer.")] public: Segment* Send( byte[]* buffer, int offset, int count, SocketFlags socketFlags ) | |
| C++/CLI | |
|---|---|
[DescriptionAttribute("Send data from your buffer.")] public: Segment^ Send( array<byte>^ buffer, int offset, int count, SocketFlags socketFlags ) | |
Parameters
- buffer
- Source memory location for the data to send.
- offset
- Starting offset within buffer for sending.
- count
- Number of bytes to send.
- socketFlags
- A bitwise combination of special use sending parameters.
Return Value
A Segment object encapsulating information about the data sent.| Exception | Description |
|---|---|
| System.ArgumentOutOfRangeException | offset or count is less than 0. |
| System.ArgumentException | offset + count is greater than the length of buffer. |
| System.Net.Sockets.SocketException | The socket is not connected. |
The following example demonstrates sending bytes to the server with a SocketFlag option.
| Visual Basic | Copy Code |
|---|---|
Private Sub Test() ' Connect to an echo port Tcp1.Connect("atropos", 7) Dim sendbuffer() As Byte = System.Text.Encoding.Default.GetBytes("abcdefg") ' Send some bytes with "OutOfBand" SocketFlag option Tcp1.Send(sendbuffer, 0, sendbuffer.Length, SocketFlags.OutOfBand) Dim recvbuffer(sendbuffer.Length) As Byte ' Server will echo the bytes back. Receive the bytes. Tcp1.Receive(recvbuffer, 0, recvbuffer.Length, SocketFlags.None) ' Close the connection. Tcp1.Close() End Sub | |
| C# | Copy Code |
|---|---|
private void Test() { // Connect to the echo port tcp1.Connect("atropos", 7); byte[] sendbuffer = System.Text.Encoding.Default.GetBytes("abcdefg"); // Send some bytes with "OutOfBand" SocketFlag option tcp1.Send(sendbuffer, 0, sendbuffer.Length, SocketFlags.OutOfBand); byte[] recvbuffer = new byte[sendbuffer.Length]; // Server will echo the bytes back. Receive the bytes. tcp1.Receive(recvbuffer, 0, recvbuffer.Length, SocketFlags.None); // Close the connection. tcp1.Close(); } | |
After connecting, data can be received using the Tcp.Send method. All Tcp.Send methods return a Segment object, encapsulating information about the data sent such as the data sent, and the amount of bytes of data sent.
This method is the only way to send data to a host while specifying a SocketFlags parameter.
Target Platforms: Microsoft .NET Framework 2.0